// app.js
App({
  onLaunch() {
    // 应用启动时的初始化操作
    console.log('应用启动');
  },
  
  globalData: {
    userInfo: null,
    token: null
  },
  
  // 设置全局用户信息
  setUserInfo(userInfo) {
    this.globalData.userInfo = userInfo;
    wx.setStorageSync('userInfo', userInfo);
  },
  
  // 设置全局token
  setToken(token) {
    this.globalData.token = token;
    wx.setStorageSync('token', token);
  },
  
  // 清除登录状态
  clearLoginStatus() {
    this.globalData.userInfo = null;
    this.globalData.token = null;
    wx.removeStorageSync('userInfo');
    wx.removeStorageSync('token');
  },
  
  // 获取当前登录状态
  getLoginStatus() {
    const token = wx.getStorageSync('token');
    const userInfo = wx.getStorageSync('userInfo');
    
    if (token) {
      this.globalData.token = token;
      this.globalData.userInfo = userInfo;
    }
    
    return !!token;
  }
})
